﻿<Window x:Class="TransportAnalizer_2._0.Views.NodeTypeView"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        mc:Ignorable="d"
        d:DataContext="{d:DesignInstance viewModels:NodeTypeViewModel}"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:data="clr-namespace:TransportAnalizer_2._0.Model"
        xmlns:local="clr-namespace:TransportAnalizer_2._0.Views"
        xmlns:viewModels="clr-namespace:TransportAnalizer_2._0.ViewModels"
        xmlns:helpClasses="clr-namespace:TransportAnalizer.HelpClasses;assembly=TransportAnalizer.HelpClasses"
        xmlns:ACB="clr-namespace:AttachedCommandBehavior;assembly=AttachedCommandBehavior"
        Title="MainWindow" Height="350" Width="887"
        ACB:CommandBehavior.Event="Loaded"
        ACB:CommandBehavior.Command="{Binding GetNodeTypeListCommand}">
    <Window.Resources>
        <BooleanToVisibilityConverter x:Key="VisibilityConverter"/>
        <Style TargetType="Label">
            <Setter Property="Padding" Value="0"/>
        </Style>
    </Window.Resources>
    
    <DockPanel Margin="30">
        <DockPanel DockPanel.Dock="Left" Width="500" Margin="0,0,32,0">
            <TextBlock DockPanel.Dock="Top">
                <Hyperlink Command="{Binding AddCommand}">Добавить тип узла</Hyperlink>
                <Hyperlink Command="{Binding GetNodeTypeListCommand}">Обновить список</Hyperlink>
            </TextBlock>
            <ListBox ItemsSource="{Binding NodeTypes}" SelectedItem="{Binding SelectedNodeType}">
                <ListBox.Resources>
                    <DataTemplate DataType="{x:Type data:NodeType}">
                        <TextBlock>
                            <TextBlock.Text>
                                <MultiBinding StringFormat="{} {0} ({1})">
                                    <Binding Path="Name"/>
                                    <Binding Path="Description"/>
                                </MultiBinding>
                            </TextBlock.Text>
                        </TextBlock>
                    </DataTemplate>
                </ListBox.Resources>
            </ListBox>
        </DockPanel>
        <StackPanel DockPanel.Dock="Right" Visibility="{Binding CanModify, Converter={StaticResource VisibilityConverter}}">
            <Label>Имя</Label>
            <TextBox Text="{Binding SelectedNodeType.Name, 
                                    ValidatesOnDataErrors=True, 
                                    UpdateSourceTrigger=PropertyChanged}" />
            <Label>Описание</Label>
            <TextBox Text="{Binding SelectedNodeType.Description, 
                                    ValidatesOnDataErrors=True, 
                                    UpdateSourceTrigger=PropertyChanged}" />

            <Label>Пропускная способность (машин в час)</Label>
            <TextBox Text="{Binding SelectedNodeType.Passage, 
                                    ValidatesOnDataErrors=True, 
                                    UpdateSourceTrigger=PropertyChanged}" />
            <Label>Тип регулирования</Label>
            <ComboBox SelectedItem="{Binding SelectedNodeType.Regulation, 
                                    ValidatesOnDataErrors=True, 
                                    UpdateSourceTrigger=PropertyChanged, 
                                    Mode=TwoWay}"
                      local:EnumHelper.Enum="{x:Type data:RegulationType}" SelectionChanged="RefreshComboBoxSelection">
                <ComboBox.ItemTemplate>
                    <DataTemplate>
                        <TextBlock local:EnumHelper.MoreDetails="True"/>
                    </DataTemplate>
                </ComboBox.ItemTemplate>
            </ComboBox>
            <TextBlock>
                <Hyperlink Command="{Binding UpdateCommand}">Сохранить</Hyperlink>
                <Hyperlink Command="{Binding DeleteCommand}">Удалить</Hyperlink>
            </TextBlock>
        </StackPanel>
    </DockPanel>
</Window>
